package com.qdlc.p2p.biz.processor.task.collection;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.core.tender.BorrowStrategyContextFactory;
import com.qdlc.p2p.biz.processor.event.BorrowValueEvent;
import com.qdlc.p2p.biz.processor.task.AbstractTaskProcessor;
import com.qdlc.p2p.common.constant.BorrowCategory;
import com.qdlc.p2p.common.constant.BorrowType;
import com.qdlc.p2p.common.core.queue.TaskProcessorException;
import com.qdlc.p2p.common.core.queue.ValueEvent;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.model.BorrowModel;

/**
 * PS 投标代收
 *
 * @author wuaj
 */
@Service
public class TenderTaskProcessor extends AbstractTaskProcessor {

    @Override
    public boolean supports(ValueEvent event) {
        return event instanceof BorrowValueEvent;
    }

    @Override
    public void process0(ValueEvent event) throws TaskProcessorException {
        BorrowValueEvent borrowEvent = (BorrowValueEvent) event;

        BorrowModel borrowModel = borrowEvent.getBorrowModel(); // 标信息
        User tenderUser = borrowEvent.getUser(); // 投标用户
        // 体验标 策略进行投标
        if (borrowModel.getCategory() == BorrowCategory.EXPERIENCE) {
            BorrowStrategyContextFactory.getBorrowStrategy(BorrowType.EXPERIENCE).tender(borrowModel, tenderUser);
        } else {
            BorrowStrategyContextFactory.getBorrowStrategy(borrowModel.getType()).tender(borrowModel, tenderUser);
        }
    }
}